//
//  SmallDecisions.m
//  SmallDecisions
//
//  Created by 李付雄 on 2025/11/2.
//

#import "SceneDelegate.h"
#import <IQKeyboardManager.h>
#import "SmallDecisionsBaseTabBarController.h"
#import "SmallDecisionsGoogleAdsHelper.h"
#import "SmallDecisionsIAPHelper.h"

@interface SceneDelegate ()

@end

@implementation SceneDelegate


- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
    if (@available(iOS 13.0, *)) {
        SmallDecisionsBaseTabBarController *mainTabBarController = [[SmallDecisionsBaseTabBarController alloc] init];
        [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
        [SmallDecisionsGoogleAdsHelper startRegisterGoogleMobileAds];
        UIWindowScene *windowScene = (UIWindowScene *)scene;
        self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
        self.window.frame = windowScene.coordinateSpace.bounds;
        self.window.rootViewController = mainTabBarController;
        [self.window makeKeyAndVisible];
    }
}



- (void)sceneDidBecomeActive:(UIScene *)scene {
    static dispatch_once_t onceToken;
#ifndef DEBUG
    dispatch_once(&onceToken, ^{

        [SmallDecisionsGoogleAdsHelper startLoadGoogleLaunchMobileAdsWithController:[SmallDecisionsSingletonHelper getKeyWindow].rootViewController failureBlock:nil];
        [SmallDecisionsIAPHelper applePayIAPRestoreProductSuccessBlock:nil failedBlock:nil];
    });
#endif
}


- (void)sceneWillEnterForeground:(UIScene *)scene {
#ifndef DEBUG
    [SmallDecisionsGoogleAdsHelper
     startLoadGoogleLaunchMobileAdsWithController:[SmallDecisionsSingletonHelper getKeyWindow].rootViewController failureBlock:nil];
#endif
}

@end
